package LeetCode.month02.day37;

public class No14 {
    public String longestCommonPrefix(String[] strs) {
        int n = strs.length;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strs[0].length(); i++) {
            char c = strs[0].charAt(i);
            for (int j = 1; j < n; j++) {
                if(i==strs[j].length()) return strs[j];
                if(strs[j].charAt(i)!=c) return sb.toString();
            }
            sb.append(c);
        }
        return sb.toString();
    }
}
